/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/5/2
 * \* Time: 12:23
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class 调整数组顺序使奇数位于偶数前面 {
    public static int[] exchange(int[] nums) {
        int left=0;
        int right=nums.length-1;
        while(left<right){
            while(left<=right&&(nums[left]&1)!=0){
                left++;
            }
            while(left<=right&&(nums[right]&1)!=1){
                right--;
            }
            if(left>right){
                break;
            }
            int temp=nums[left];
            nums[left]=nums[right];
            nums[right]=temp;
        }
        return nums;
    }

    public static void main(String[] args) {
        int[]nums=new int[]{1,2,3,4};
        exchange(nums);
        System.out.print(nums);
    }
}